package com.bruce.ai.alibaba.agentcard.discovery.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
import java.util.Map;

/**
 * A2A响应模型，用于Agent间通信
 * 基于Google A2A协议标准设计
 */
public class A2AResponse {
    
    @JsonProperty("id")
    private String id;
    
    @JsonProperty("request_id")
    private String requestId;
    
    @JsonProperty("timestamp")
    private Instant timestamp;
    
    @JsonProperty("source_agent")
    private String sourceAgent;
    
    @JsonProperty("target_agent")
    private String targetAgent;
    
    @JsonProperty("status")
    private String status;
    
    @JsonProperty("message")
    private String message;
    
    @JsonProperty("error_code")
    private String errorCode;
    
    @JsonProperty("error_message")
    private String errorMessage;
    
    @JsonProperty("data")
    private Object data;
    
    @JsonProperty("error")
    private ErrorInfo error;
    
    @JsonProperty("metadata")
    private Map<String, Object> metadata;
    
    @JsonProperty("processing_time_ms")
    private Long processingTimeMs;
    
    public A2AResponse() {
        this.timestamp = Instant.now();
        this.status = "SUCCESS";
    }
    
    public A2AResponse(String requestId, String sourceAgent, String targetAgent) {
        this();
        this.requestId = requestId;
        this.sourceAgent = sourceAgent;
        this.targetAgent = targetAgent;
    }
    
    // Getters and Setters
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getRequestId() {
        return requestId;
    }
    
    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
    
    public Instant getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(Instant timestamp) {
        this.timestamp = timestamp;
    }
    
    public String getSourceAgent() {
        return sourceAgent;
    }
    
    public void setSourceAgent(String sourceAgent) {
        this.sourceAgent = sourceAgent;
    }
    
    public String getTargetAgent() {
        return targetAgent;
    }
    
    public void setTargetAgent(String targetAgent) {
        this.targetAgent = targetAgent;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public Object getData() {
        return data;
    }
    
    public void setData(Object data) {
        this.data = data;
    }
    
    public ErrorInfo getError() {
        return error;
    }
    
    public void setError(ErrorInfo error) {
        this.error = error;
    }
    
    public Map<String, Object> getMetadata() {
        return metadata;
    }
    
    public void setMetadata(Map<String, Object> metadata) {
        this.metadata = metadata;
    }
    
    public Long getProcessingTimeMs() {
        return processingTimeMs;
    }
    
    public void setProcessingTimeMs(long processingTimeMs) {
        this.processingTimeMs = processingTimeMs;
    }
    
    public String getErrorCode() {
        return errorCode;
    }
    
    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public enum Status {
        SUCCESS, ERROR, TIMEOUT, REJECTED, PROCESSING
    }
    
    public static class ErrorInfo {
        @JsonProperty("code")
        private String code;
        
        @JsonProperty("message")
        private String message;
        
        @JsonProperty("details")
        private String details;
        
        public ErrorInfo() {}
        
        public ErrorInfo(String code, String message) {
            this.code = code;
            this.message = message;
        }
        
        public ErrorInfo(String code, String message, String details) {
            this.code = code;
            this.message = message;
            this.details = details;
        }
        
        // Getters and Setters
        public String getCode() {
            return code;
        }
        
        public void setCode(String code) {
            this.code = code;
        }
        
        public String getMessage() {
            return message;
        }
        
        public void setMessage(String message) {
            this.message = message;
        }
        
        public String getDetails() {
            return details;
        }
        
        public void setDetails(String details) {
            this.details = details;
        }
        
        @Override
        public String toString() {
            return "ErrorInfo{" +
                    "code='" + code + '\'' +
                    ", message='" + message + '\'' +
                    ", details='" + details + '\'' +
                    '}';
        }
    }
    
    @Override
    public String toString() {
        return "A2AResponse{" +
                "id='" + id + '\'' +
                ", requestId='" + requestId + '\'' +
                ", timestamp=" + timestamp +
                ", sourceAgent='" + sourceAgent + '\'' +
                ", targetAgent='" + targetAgent + '\'' +
                ", status=" + status +
                ", message='" + message + '\'' +
                ", processingTimeMs=" + processingTimeMs +
                '}';
    }
}